package com.stylefeng.guns.rest.modular.wz.api.v3;

import com.aliyuncs.dysmsapi.model.v20170525.SendSmsResponse;
import com.baomidou.mybatisplus.mapper.Condition;
import com.baomidou.mybatisplus.mapper.EntityWrapper;
import com.baomidou.mybatisplus.plugins.Page;
import com.stylefeng.guns.rest.common.base.controller.ApiBaseController;
import com.stylefeng.guns.rest.common.constant.Consts;
import com.stylefeng.guns.rest.common.persistence.dao.*;
import com.stylefeng.guns.rest.common.persistence.model.*;
import com.stylefeng.guns.rest.common.util.AliyunSmsUtil;
import com.stylefeng.guns.rest.common.util.StringUtils;
import com.stylefeng.guns.rest.domain.ParamMap;
import com.stylefeng.guns.rest.domain.Res;
import com.stylefeng.guns.rest.enums.EnWzCoupon;
import com.stylefeng.guns.rest.enums.EnWzMapMerge;
import com.stylefeng.guns.rest.modular.auth.util.JwtTokenUtil;
import com.stylefeng.guns.rest.modular.wz.api.v1.WzCommonApi;
import com.stylefeng.guns.rest.modular.wz.cache.CacheService;
import com.stylefeng.guns.rest.modular.wz.controller.WzShareApi;
import com.stylefeng.guns.rest.modular.wz.service.impl.WzUserMergeServiceImpl;
import com.stylefeng.guns.rest.modular.wz.util.wz.DateUtil;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.*;

/**
 * @program: wz_dev_app_shop
 * @description: 周边店铺拼单
 * @author: Chenchao
 * @create: 2019-02-27 09:38
 **/
@RestController
@RequestMapping("/wz/api/v3/mapMerge/")
public class WzMapMergeApi extends ApiBaseController {
    protected final static Logger logger = LoggerFactory.getLogger(WzMapMergeApi.class);
    @Autowired
    private WzMapMergeMapper mapMergeMapper;
    @Autowired
    private WzUserMergeMapper userMergeMapper;
    @Autowired
    private WzAdvMapMapper advMapMapper;
    @Autowired
    private WzCouponMapper couponMapper;
    @Autowired
    private CacheService cacheService;
    @Autowired
    private JwtTokenUtil jwtTokenUtil;
    @Autowired
    private WzUserMapper userMapper;
    @Autowired
    private WzUserMergeServiceImpl userMergeService;
    @Autowired
    private WzUserMergeDetailMapper userMergeDetailMapper;
    @Autowired
    private WzUserCouponMapper userCouponMapper;
    @Autowired
    private WzShareApi shareApi;


    /**
     * 拼单列表
     */
    @PostMapping("list")
    public Res list(@RequestBody ParamMap paramMap) {
        int pageNum = paramMap.getIntMisValid("pageNum");
        int pageSize = paramMap.getIntMisValid("pageSize");
        String switchAdCode = paramMap.getStrMisValid("switchAdCode");
        Integer advMapCategoryFirst = paramMap.getIntValid("advMapCategoryFirst");//0:全部
        Long advMapId = paramMap.getLongValid("advMapId");
        Long userCode=jwtTokenUtil.getUserCodeFromToken();
        String keyWords = paramMap.getStrValid("keyWords");//搜索关键字


        //拼单列表获取
        EntityWrapper ew = new EntityWrapper<WzMapMerge>();
        if (advMapCategoryFirst != 0) {
            ew.eq("adv_map_category_first",advMapCategoryFirst);
        }
        if(StringUtils.isNotBlank(keyWords)){
            String filterSql = "(merchant_name like '%" + keyWords+"%' or benefit like '%"+keyWords+"%')";
            ew.addFilter(filterSql);
        }
        if(advMapCategoryFirst == 0 && StringUtils.isBlank(keyWords)){
            ew.eq("is_recommend",1);
        }
        if(advMapId != null){//单个店铺活动
            ew.eq("adv_map_id",advMapId);
        }
        //拼单活动列表
        String sql = "map_merge_id AS mapMergeId,merchant_name AS merchantName,benefit,merge_price AS mergePrice,sales,pic";
        List<Map<String, Object>> mergeList = mapMergeMapper.selectMapsPage(new Page<>(pageNum, pageSize), ew.setSqlSelect(sql).like("ad_code",switchAdCode).eq("status", EnWzMapMerge.STATUS_RELEASE.getIndex()).orderBy("sort",true).orderBy("create_time",false));
        paramMap.put("mergeList",mergeList);
        //用户发起拼单列表
        String userMergeDetailsSql = "user_merge_id AS userMergeId,end_time AS endTime,status,benefit,pic,adv_map_id As advMapId";
        List<Map<String, Object>> userMergeDetailList = userMergeDetailMapper.selectMaps(new EntityWrapper<WzUserMergeDetail>().setSqlSelect(userMergeDetailsSql).eq("user_code",userCode).eq("status",EnWzMapMerge.UserMapMergeDetail_OnGoing.getIndex()));
        for(Map<String, Object> map : userMergeDetailList){
            WzAdvMap advMap = cacheService.advMap(Long.parseLong(map.get("advMapId").toString()));
            map.put("shareLink",advMap.getShareLink());
            map.put("title","我正在参与'" + advMap.getName() +"'的拼单活动,一起来拼单享更多优惠!");
            map.put("shareDescribe",advMap.getSubtitle());
        }
        paramMap.put("userMergeList",userMergeDetailList);
        return Res.success(paramMap);
    }

    /**
     * 新增拼单
     */
    @PostMapping("add")
    public Res add(@RequestBody ParamMap paramMap) throws Exception{
        Long couponId = paramMap.getLongMisValid("couponId");
        int mergePrice = paramMap.getIntMisValid("mergePrice");
        String beginTimeX = paramMap.getStrMisValid("beginTime");//活动开始时间
        Date beginTime = DateUtil.toDateTime(beginTimeX + " 00:00:00");
        String endTimeX = paramMap.getStrMisValid("endTime");//活动结束时间
        Date endTime = DateUtil.toDateTime(endTimeX + " 23:59:59");
        int totalNumber = paramMap.getIntMisValid("totalNumber");
        int limitNumber = paramMap.getIntMisValid("limitNumber");//每人限购多少件

        WzCoupon coupon = cacheService.coupon(couponId);
        WzAdvMap advMap=cacheService.advMap(Long.parseLong(coupon.getAdvMapId()));
        //时间判断
        if(endTime.after(coupon.getEndTime())){
            return Res.fail("结束时间不能晚于礼券结束时间！");
        }
        if(beginTime.before(coupon.getBeginTime())){
            return Res.fail("开始时间不能早于礼券开始时间！");
        }
        if(totalNumber < 1){
            return Res.fail("总数量不能小于1件！");
        }
        if(limitNumber < 1){
            return Res.fail("每人限购数量不能小于1件！");
        }
        if(totalNumber <= limitNumber){
            return Res.fail("每人限购数量不能大于等于总数量");
        }
        if(mergePrice >= coupon.getPrice()){
            return Res.fail("拼单价不能大于原价!");
        }

        WzMapMerge mapMerge = new WzMapMerge();
        mapMerge.setMergePrice(mergePrice);
        mapMerge.setStatus(EnWzMapMerge.STATUS_CHECKING.getIndex());
        mapMerge.setAdvMapCategoryFirst(advMap.getAdvMapCategoryFirst());
        mapMerge.setBeginTime(beginTime);
        mapMerge.setEndTime(endTime);
        mapMerge.setCreateTime(new Date());
        mapMerge.setTotalNumber(totalNumber);
        mapMerge.setLimitNumber(limitNumber);
        mapMerge.setAdvMapId(Long.parseLong(coupon.getAdvMapId()));
        mapMerge.setCouponId(couponId);
        mapMerge.setSurplusNumber(totalNumber);
        mapMerge.setPic(coupon.getPic());
        mapMerge.setMerchantName(coupon.getMerchantName());
        mapMerge.setMerchantUserCode(advMap.getUserCode());
        mapMerge.setBenefit(coupon.getBenefit());
        mapMerge.setAdCode(advMap.getAdCode());
        boolean b = mapMerge.insert();
        if (b) {
            if (Consts.dev.equals("false")) {
                for (String c : Consts.AuditorTel) {
                    SendSmsResponse response = AliyunSmsUtil.sendAdminSms(c, "有新的拼单需要审核", Consts.ADMIN_TEMPLATE_CODE);
                }
            }
            return Res.success();
        } else {
            return Res.fail();
        }
    }

    /**
     * 修改拼单
     */
    @PostMapping("edit")
    public Res edit(@RequestBody ParamMap paramMap) throws Exception{
        Long mapMergeId = paramMap.getLongMisValid("mapMergeId");
        WzMapMerge mapMerge=mapMergeMapper.selectById(mapMergeId);
        int mergePrice = paramMap.getIntMisValid("mergePrice");
        String beginTimeX = paramMap.getStrMisValid("beginTime");//活动开始时间
        Date beginTime = DateUtil.toDateTime(beginTimeX + " 00:00:00");
        String endTimeX = paramMap.getStrMisValid("endTime");//活动结束时间
        Date endTime = DateUtil.toDateTime(endTimeX + " 23:59:59");
        int limitNumber = paramMap.getIntMisValid("limitNumber");//每人限购多少件
        int totalNumber = paramMap.getIntMisValid("totalNumber");

        if(totalNumber < 1){
            return Res.fail("总数量不能小于1件！");
        }
        if(limitNumber < 1){
            return Res.fail("每人限购数量不能小于1件！");
        }
        if(totalNumber <= limitNumber){
            return Res.fail("每人限购数量不能大于等于总数量");
        }

        Map<String, Object> coupon = cacheService.couponData(mapMerge.getCouponId());
        Date couponBeginTime = DateUtil.toDateTime(coupon.get("beginTime").toString());
        Date couponEndTime = DateUtil.toDateTime(coupon.get("endTime").toString());
        if(endTime.after(couponEndTime)){
            return Res.fail("结束时间不能晚于礼券结束时间！");
        }
        if(beginTime.before(couponBeginTime)){
            return Res.fail("开始时间不能早于礼券开始时间！");
        }
        mapMerge.setSurplusNumber(totalNumber);
        mapMerge.setTotalNumber(totalNumber);
        mapMerge.setLimitNumber(limitNumber);
        mapMerge.setBeginTime(beginTime);
        mapMerge.setEndTime(endTime);
        mapMerge.setMergePrice(mergePrice);
        mapMerge.setStatus(EnWzMapMerge.STATUS_CHECKING.getIndex());
        int r = mapMergeMapper.updateById(mapMerge);
        if (r > 0) {
            if (Consts.dev.equals("false")) {
                for (String c : Consts.AuditorTel) {
                    SendSmsResponse response = AliyunSmsUtil.sendAdminSms(c, "有拼单修改需要审核", Consts.ADMIN_TEMPLATE_CODE);
                }
            }
            return Res.success();
        } else {
            return Res.fail();
        }
    }

    /**
     * 拼单详情
     */
    @PostMapping("detail")
    public Res detail(@RequestBody ParamMap paramMap) {
        Long mapMergeId=paramMap.getLongMisValid("mapMergeId");
        Long userCode=jwtTokenUtil.getUserCodeFromToken();
        //基本信息
        WzMapMerge mapMerge = mapMergeMapper.selectById(mapMergeId);
        WzAdvMap advMap = cacheService.advMap(mapMerge.getAdvMapId());//店铺信息
        WzCoupon coupon = cacheService.coupon(mapMerge.getCouponId());//券信息

        paramMap.put("pic",mapMerge.getPic());//拼单图片
        paramMap.put("advMapId",mapMerge.getAdvMapId());//店铺id
        paramMap.put("mergePrice",mapMerge.getMergePrice());//拼单价
        paramMap.put("merchantName",mapMerge.getMerchantName());//商户名称
        paramMap.put("merchantUserCode",mapMerge.getMerchantUserCode());//商户编号
        paramMap.put("merchantTel",advMap.getMerchantTel());//商户编号
        paramMap.put("benefit",mapMerge.getBenefit());//优惠信息
        paramMap.put("sales",mapMerge.getSales());//销量
        paramMap.put("couponBeginTime",coupon.getBeginTime());//券的开始时间
        paramMap.put("couponEndTime",coupon.getEndTime());//券的结束时间
        paramMap.put("rule",coupon.getRule());//券的使用规则
        paramMap.put("ruleType",coupon.getRuleType());//券的类型：1-文字；2-图片；
        paramMap.put("advMapShareLink",advMap.getShareLink());//店铺详情
        paramMap.put("price",coupon.getPrice());//券原价
        paramMap.put("logo",advMap.getLogo());//店铺logo
        paramMap.put("title",advMap.getName()+"在外赚有很多优惠活动，快去看看吧！");//分享标题
        paramMap.put("shareDescribe",advMap.getSubtitle());//分享描述
//        paramMap.put("shareLink",advMap.getShareLink());//分享链接
        int isDev;
        if (Consts.dev.equals("true")) {
            isDev=1;
        }else{
            isDev=0;
        }
        String shareLink=advMap.getShareLink()+"?advMapId="+mapMerge.getAdvMapId()+"&showMapMerge=1&isDev="+isDev+"&shareTitle="+shareApi.getURLEncoderString(paramMap.get("title").toString())+"&shareImg="+shareApi.getURLEncoderString(paramMap.get("pic").toString());
        paramMap.put("shareLink",shareLink);//分享链接
        paramMap.put("couponId",coupon.getCouponId());//券id
        paramMap.put("useType",coupon.getUseType());//使用方式
        int quantity = 0;
        List<Map<String, Object>> quantitys = userMergeDetailMapper.selectMaps(Condition.create().setSqlSelect("sum(quantity) As quantity").eq("user_code",userCode).eq("map_merge_id",mapMerge.getMapMergeId()).in("status",new Integer[]{EnWzMapMerge.UserMapMergeDetail_OnGoing.getIndex(),EnWzMapMerge.UserMapMergeDetail_Finish.getIndex()}));
        if(quantitys.get(0) != null){
            quantity = Integer.parseInt(quantitys.get(0).get("quantity").toString());
        }
        int limitNumber = mapMerge.getLimitNumber() - quantity;
        if(limitNumber <= 0){
            limitNumber = 0;
        }else{
            if(limitNumber > mapMerge.getSurplusNumber()){
                limitNumber = mapMerge.getSurplusNumber();
            }
        }
        if(mapMerge.getSurplusNumber() <= 0){
            limitNumber = 0;
        }
        paramMap.put("limitNumber",limitNumber);//限购数量
        //自己发起拼单列表
        String userMergeDetailistSql = "user_merge_id AS userMergeId,end_time AS endTime,status,benefit,pic,avatar_url As firstAvatarUrl";
        List<Map<String, Object>> userMergeDetailList = userMergeDetailMapper.selectMaps(new EntityWrapper<WzUserMergeDetail>().setSqlSelect(userMergeDetailistSql).eq("map_merge_id",mapMerge.getMapMergeId()).eq("user_code",userCode).eq("status",EnWzMapMerge.UserMapMergeDetail_OnGoing.getIndex()));
        for(Map<String, Object> map : userMergeDetailList){
            map.put("shareLink",shareLink);
            map.put("title","我正在参与'" + advMap.getName() +"'的拼单活动,一起来拼单享更多优惠!");
            map.put("shareDescribe",advMap.getSubtitle());
        }
        paramMap.put("myUserMergeList",userMergeDetailList);

        //用户发起拼单列表
        int userMergeNumber = userMergeDetailMapper.selectCount(new EntityWrapper<WzUserMergeDetail>().eq("map_merge_id",mapMerge.getMapMergeId()).eq("status",EnWzMapMerge.UserMapMergeDetail_OnGoing.getIndex()));
        paramMap.put("userMergeNumber",userMergeNumber);
        if(userMergeNumber > 0){
            String userMergeDetailistsSql = "user_code As userCode,user_merge_id AS userMergeId,end_time AS endTime,status,benefit,pic,avatar_url As avatarUrl,nick_name As nickName";
            List<Map<String, Object>> userMergeDetailists = userMergeDetailMapper.selectMaps(new EntityWrapper<WzUserMergeDetail>().setSqlSelect(userMergeDetailistsSql).eq("map_merge_id",mapMerge.getMapMergeId()).eq("status",EnWzMapMerge.UserMapMergeDetail_OnGoing.getIndex()));
            paramMap.put("allUserMergeList",userMergeDetailists);
        }else{
            paramMap.put("allUserMergeList",new ArrayList<>());
        }
        return Res.success(paramMap);
    }

    /**
     * 用户拼单列表
     */
    @PostMapping("userList")
    public Res userList(@RequestBody ParamMap paramMap) {
        int pageNum = paramMap.getIntMisValid("pageNum");
        int pageSize = paramMap.getIntMisValid("pageSize");
        String userCode = paramMap.getStrValid("userCode");
        String mapMergeId = paramMap.getStrValid("mapMergeId");
        String sql = "user_merge_id AS userMergeId, map_merge_id AS mapMergeId, user_code AS userCode, nick_name AS nickName, avatar_url AS avatarUrl, coupon_id AS couponId,join_number AS joinNumber, end_time AS endTime";
        EntityWrapper ew = new EntityWrapper<WzUserMerge>();
        if (userCode != null) {
            ew.like("user_code", userCode);
        }
        if(mapMergeId != null){
            ew.eq("map_merge_id",mapMergeId);
        }
        List<Map<String, Object>> list = userMergeMapper.selectMapsPage(new Page<>(pageNum, pageSize), ew.setSqlSelect(sql).eq("status", EnWzMapMerge.USERMERGE_STATUS_GOING.getIndex()));
        return Res.success(paramMap.data(list));
    }

    /**
     * 下架拼单活动
     */
    @PostMapping("pullOff")
    public Res pullOff(@RequestBody ParamMap paramMap) {
        Long mapMergeId = paramMap.getLongMisValid("mapMergeId");
        WzMapMerge mapMerge = mapMergeMapper.selectById(mapMergeId);
        if(mapMerge.getStatus()!=EnWzMapMerge.STATUS_RELEASE.getIndex()){
            return Res.fail("当前状态不可下架！");
        }
        mapMerge.setStatus(EnWzMapMerge.STATUS_Down.getIndex());
        int r=mapMergeMapper.updateById(mapMerge);
        if(r > 0){
            return Res.success();
        }else{
            return Res.fail();
        }
    }

    /**
     * 去拼单
     */
    @PostMapping("createMerge")
    public Res createMerge(@RequestBody ParamMap paramMap) throws Exception{
        Long userMergeId = paramMap.getLongValid("userMergeId");//用户拼单id
        Long userCode = jwtTokenUtil.getUserCodeFromToken();//下单用户编号
        Long mapMergeId = paramMap.getLongMisValid("mapMergeId");
        int quantity = paramMap.getIntMisValid("quantity");//购买数量

        WzMapMerge mapMerge = mapMergeMapper.selectById(mapMergeId);//拼单活动

        int c = 0;
        List<Map<String, Object>> quantitys = userMergeDetailMapper.selectMaps(Condition.create().setSqlSelect("sum(quantity) As quantity").eq("user_code",userCode).eq("map_merge_id",mapMerge.getMapMergeId()).in("status",new Integer[]{EnWzMapMerge.UserMapMergeDetail_OnGoing.getIndex(),EnWzMapMerge.UserMapMergeDetail_Finish.getIndex()}));
        if(quantitys.get(0) != null){
            c = Integer.parseInt(quantitys.get(0).get("quantity").toString());
        }
        int limitNumber = mapMerge.getLimitNumber() - c;
        if(mapMerge.getSurplusNumber() < 0){
            limitNumber = 0;
        }
        if(limitNumber <= 0){
            return Res.fail("此商品已达限购数量!");
        }
        if(limitNumber > mapMerge.getSurplusNumber()){
            limitNumber = mapMerge.getSurplusNumber();
        }
        if(quantity > limitNumber){
            return Res.fail("此商品你最多只能买"+ limitNumber + "件");
        }
        if(userMergeId == null){//用户发起拼单
            Res res = userMergeService.createMerge(paramMap);
            return res;
        }else{//用户参与拼单
            Res res = userMergeService.joinMerge(paramMap);
            return res;
        }
    }

    /**
     * 拼单支付成功
     */
    @PostMapping("createMergeSuccess")
    public Res createMergeSuccess(@RequestBody ParamMap paramMap) throws Exception{
        Long userCode=jwtTokenUtil.getUserCodeFromToken();
        Long userMergeDetailId = paramMap.getLongMisValid("userMergeDetailId");//用户拼单id

        WzUserMergeDetail userMergeDetail = userMergeDetailMapper.selectById(userMergeDetailId);
        WzMapMerge mapMerge = mapMergeMapper.selectById(userMergeDetail.getMapMergeId());
        WzUserMerge userMerge = userMergeMapper.selectById(userMergeDetail.getUserMergeId());
        WzAdvMap advMap = cacheService.advMap(userMergeDetail.getAdvMapId());

        paramMap.put("status",userMergeDetail.getStatus());
        paramMap.put("endTime",userMergeDetail.getEndTime());
        String benefit = "【"+mapMerge.getMerchantName()+"】" + mapMerge.getBenefit();
        paramMap.put("benefit",benefit);

        paramMap.put("shareLink",advMap.getShareLink());
        paramMap.put("title","我正在参与'" + advMap.getName() +"'的拼单活动,一起来拼单享更多优惠!");
        paramMap.put("shareDescribe",advMap.getSubtitle());
        paramMap.put("pic",mapMerge.getPic());

        if(userCode.toString().equals(userMerge.getUserCode().toString())){
            paramMap.put("firstAvatarUrl",userMerge.getAvatarUrl());
            paramMap.put("secondAvatarUrl","");
        }else{
            paramMap.put("firstAvatarUrl",userMergeDetail.getAvatarUrl());
            paramMap.put("secondAvatarUrl",userMerge.getAvatarUrl());
        }
        return Res.success(paramMap);
    }

    /**
     * 我的拼单活动
     */
    @PostMapping("myUserMerges")
    public Res myUserMerges(@RequestBody ParamMap paramMap){
        Long userCode=jwtTokenUtil.getUserCodeFromToken();
        int pageNum = paramMap.getIntMisValid("pageNum");
        int pageSize = paramMap.getIntMisValid("pageSize");
        int status = paramMap.getIntMisValid("status");
        String sql = "second_avatar_url As secondAvatarUrl,merge_price As mergePrice,quantity,amount,map_merge_id As mapMergeId,user_merge_id AS userMergeId,end_time AS endTime,status,benefit,pic,adv_map_id As advMapId,avatar_url As firstAvatarUrl";
        List<Map<String, Object>> userMergeDetailList = userMergeDetailMapper.selectMapsPage(new Page<>(pageNum, pageSize),new EntityWrapper<WzUserMergeDetail>().setSqlSelect(sql).eq("user_code",userCode).eq("status",status));
        for(Map<String, Object> map : userMergeDetailList){
            if(status == EnWzMapMerge.UserMapMergeDetail_OnGoing.getIndex()){
                WzAdvMap advMap = cacheService.advMap(Long.parseLong(map.get("advMapId").toString()));
                map.put("shareLink",advMap.getShareLink());
                map.put("title","我正在参与'" + advMap.getName() +"'的拼单活动,一起来拼单享更多优惠!");
                map.put("shareDescribe",advMap.getSubtitle());
            }else if(status == EnWzMapMerge.UserMapMergeDetail_Finish.getIndex()){
                WzUserMerge userMerge = userMergeMapper.selectById(Long.parseLong(map.get("userMergeId").toString()));
                if(userCode.toString().equals(userMerge.getUserCode().toString())){
                    List<WzUserMergeDetail> userMergeDetails = userMergeDetailMapper.selectList(new EntityWrapper<WzUserMergeDetail>().ne("user_code",userCode).eq("user_merge_id",userMerge.getUserMergeId()).eq("status",EnWzMapMerge.UserMapMergeDetail_Finish.getIndex()));
                    if(userMergeDetails.size() > 0){
                        map.put("secondAvatarUrl",userMergeDetails.get(0).getAvatarUrl());
                    }
                }else{
                    map.put("secondAvatarUrl",userMerge.getAvatarUrl());
                }
            }

        }
        return Res.success(paramMap.data(userMergeDetailList));
    }

    /**
     * 拼单记录
     */
    @PostMapping("mapMergeReward")
    public Res mapMergeReward(@RequestBody ParamMap paramMap){
        int pageNum = paramMap.getIntMisValid("pageNum");
        int pageSize = paramMap.getIntMisValid("pageSize");
        Long mapMergeId = paramMap.getLongMisValid("mapMergeId");

        String sql = "nick_name AS nickName,avatar_url AS avatarUrl,create_time As createTime,quantity,status";
        List<Map<String, Object>> userMergeDetailList = userMergeDetailMapper.selectMapsPage(new Page<>(pageNum, pageSize),new EntityWrapper<WzUserMergeDetail>().setSqlSelect(sql).eq("map_merge_id",mapMergeId).in("status",new Integer[]{EnWzMapMerge.UserMapMergeDetail_OnGoing.getIndex(),EnWzMapMerge.UserMapMergeDetail_Finish.getIndex()}));
        return Res.success(paramMap.data(userMergeDetailList));
    }
}
